import Vue from 'vue'
import App from './App.vue'
import router from './router/index.js'
// import Axios from 'axios'
import Auth from './network/auth.js'
Vue.use(Auth)


import { Button } from 'vant';
Vue.use(Button); // 全局使用
import { NavBar } from 'vant';
Vue.use(NavBar);
import { Tab, Tabs } from 'vant';
Vue.use(Tab);
Vue.use(Tabs);
import { Form } from 'vant';
Vue.use(Form);
import { Field } from 'vant';
Vue.use(Field);
import { Tabbar, TabbarItem } from 'vant';
Vue.use(Tabbar);
Vue.use(TabbarItem);
import { Search } from 'vant';
Vue.use(Search);
import { Cell, CellGroup } from 'vant';
Vue.use(Cell);
Vue.use(CellGroup);
import { NoticeBar } from 'vant';
Vue.use(NoticeBar);
import { Col, Row } from 'vant';
Vue.use(Col);
Vue.use(Row);
import { Image as VanImage } from 'vant';
Vue.use(VanImage);
import { Tag } from 'vant';
Vue.use(Tag);
import { ShareSheet,Cascader,Popup  } from 'vant';
Vue.use(ShareSheet).use(Cascader).use(Popup);
import { Step, Steps } from 'vant';
Vue.use(Step);
Vue.use(Steps);
import { Loading } from 'vant';
Vue.use(Loading);
import { PullRefresh } from 'vant';
Vue.use(PullRefresh);
import { Uploader } from 'vant';
Vue.use(Uploader);
import { Empty } from 'vant';
Vue.use(Empty);
import { List } from 'vant';
Vue.use(List);
import { Icon } from 'vant';
Vue.use(Icon);
import { Divider } from 'vant';
Vue.use(Divider);
import { Collapse, CollapseItem } from 'vant';
Vue.use(Collapse);
Vue.use(CollapseItem);
import { Picker } from 'vant';
Vue.use(Picker);
import { Circle } from 'vant';
Vue.use(Circle);
import { Dialog } from 'vant';
Vue.use(Dialog);
import { CountDown } from 'vant';
Vue.use(CountDown);
import { DatetimePicker } from 'vant';
Vue.use(DatetimePicker);
import { Grid, GridItem } from 'vant';
Vue.use(Grid);
Vue.use(GridItem);
import { Switch } from 'vant';
Vue.use(Switch);
import { SwipeCell } from 'vant';
Vue.use(SwipeCell);
import { RadioGroup, Radio } from 'vant';
Vue.use(Radio);
Vue.use(RadioGroup);





// import { Toast } from 'vant'
// import { viewPersonInfo } from '@/api/person.js'
router.beforeEach((to, from, next) => {
	const auth_token = localStorage.getItem('auth_token');
  // console.log(auth_token)
  if(to.name === 'login' && auth_token) {
    next({ name: 'home' });
  } else {
      next();
  }
   
});

// if (auth_token)  {
//   viewPersonInfo().then(res => {
//     console.log(res);
//     if(res.data.code === 0){
//       if(to.name === 'login')
//       next({ name: 'home' });
//       else 
//         next();
//     } else {
//       localStorage.removeItem('userInfo');
//       localStorage.removeItem('courseInfo');
//       localStorage.removeItem('auth_token');
//       Toast('账号过期，请重新登录');
//       next({ name: 'login' });
//     }
//   }).catch(err=> {
//     console.log(err);
//     localStorage.removeItem('userInfo');
//     localStorage.removeItem('courseInfo');
//     localStorage.removeItem('auth_token');
//     Toast('账号过期，请重新登录');
//     next({ name: 'login' });
//   })
//   // if(to.name === 'login') {   // 去登录页
//   //   next({ name: 'home' }) 
//   // } else {
    
//   // }
// }
// else {
//   if(to.name === 'login')
//     next();
//   else 
//     next({ name: 'login' });
// }

new Vue({
	router: router,
  render: h => h(App),
}).$mount('#app')
Vue.config.productionTip = false;
//Vue.prototype.$axios = Axios;
